package com.sc.nft.admin.controller;

import com.sc.nft.admin.request.*;
import com.sc.nft.annotation.SysMemberLogin;
import com.sc.nft.entity.vo.ActivityPropsDetailVO;
import com.sc.nft.entity.vo.ActivityPropsVO;
import com.sc.nft.service.ActivityPropsService;
import com.sc.nft.sup.PageResult;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;


@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/admin/activityProps")
@Api(tags = "后台活动道具卡")
public class AdminActivityPropsController {

    private final ActivityPropsService activityPropsService;


    @ApiOperation(value = "新增活动道具卡", notes = "新增活动道具卡", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/add", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result addActivityProps(@Valid @RequestBody AddActivityPropsRequest request) {
        activityPropsService.addActivityProps(request.getEquityPropsId(), request.getSumCount(), request.getCreationContent(),
                request.getRelationId(), request.getRelationName(), request.getConfList(), request.getUpperLimit(), request.getIsRegisterTime(), request.getRegisterBeginTime(), request.getRegisterEndTime(), request.getConvertScenario(), request.getDaoId());
        return Result.success();
    }

    @ApiOperation(value = "更新活动道具卡", notes = "更新活动道具卡", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/update", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result updateActivityProps(@Valid @RequestBody UpdateActivityPropsRequest request) {
        activityPropsService.updateActivityProps(request.getId(), request.getRelationId(), request.getRelationName(),
                request.getConfList(), request.getUpperLimit(), request.getIsRegisterTime(), request.getRegisterBeginTime(), request.getRegisterEndTime(), request.getDaoId());
        return Result.success();
    }

    @ApiOperation(value = "删除活动道具卡", notes = "删除活动道具卡", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/delete", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result deleteActivityProps(@RequestBody IdRequest request) {
        activityPropsService.deleteActivityProps(request.getId());
        return Result.success();
    }

    @ApiOperation(value = "分页获取活动道具卡列表", notes = "分页获取活动道具卡列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/adminPage", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<ActivityPropsVO> adminPage(@RequestBody @Valid NamePageRequest request) {
        return PageResult.success(activityPropsService.adminPage(null, request.getName(), request.getConvertScenario(), request.getDaoId(), request.getPageNo(), request.getPageSize()));
    }

    @ApiOperation(value = "根据id获取道具卡详情", notes = "根据id获取道具卡详情", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/getById", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<ActivityPropsDetailVO> getActivityPropsById(@RequestBody IdRequest request) {
        return Result.success(activityPropsService.getActivityPropsById(request.getId()));
    }

    @ApiOperation(value = "上下架道具卡", notes = "上下架道具卡", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/updateStatus", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result updateStatus(@RequestBody StatusRequest request) {
        activityPropsService.updateStatus(request.getId(), request.getStatus());
        return Result.success();
    }

    @ApiOperation(value = "修改排序", notes = "修改排序", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/updateSort", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result updateSort(@RequestBody SortRequest request) {
        activityPropsService.updateSort(request.getId(), request.getSort());
        return Result.success();
    }

    @ApiOperation(value = "修改剩余数量", notes = "修改剩余数量", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/updateUsableCount", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result updateUsableCount(@RequestBody CountRequest request) {
        activityPropsService.updateUsableCount(request.getId(), request.getCount());
        return Result.success();
    }
}
